package model

import (
	"fmt"

	"github.com/dailing/levlog"
	"github.com/go-xorm/xorm"
)

var engine *xorm.Engine

func NewDB(host, dbName string) *xorm.Engine {
	levlog.Info("Init DB with:", host, ":", dbName)
	var (
		e   *xorm.Engine
		err error
	)
	e, err = xorm.NewEngine("mysql",
		fmt.Sprintf("root:123456@tcp(%s)/%s", host, dbName))
	levlog.F(err)
	err = e.Charset("utf8").Sync2(
		new(Patient),
		new(PictureBelongsTo),
		new(BinObject),
		new(User),
		// new(UiEle),
	)
	levlog.F(err)
	engine = e
	return e
}

type ObjWithOwnerInterface interface {
	SetOwner(userId int64)
	GetOwner() int64
}

type DBDInterface interface {
	Delete() error
	Get() error
	Update() error
	Insert() error
}
